/*    */ package client;
/*    */ 
/*    */ import java.io.UnsupportedEncodingException;
/*    */ import java.security.MessageDigest;
/*    */ import java.security.NoSuchAlgorithmException;
/*    */ import java.util.Random;
/*    */ import tools.HexTool;
/*    */ 
/*    */ 
/*    */ public class LoginCrypto
/*    */ {
/*    */   protected static final int extralength = 6;
/* 13 */   private static final String[] Alphabet = new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
/* 14 */   private static final String[] Number = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
/* 15 */   private static final Random rand = new Random();
/*    */   
/*    */   public static String Generate_13DigitAsiasoftPassport() {
/* 18 */     StringBuilder sb = new StringBuilder();
/* 19 */     sb.append(Alphabet[rand.nextInt(Alphabet.length)]);
/* 20 */     for (int i = 0; i < 11; i++) {
/* 21 */       sb.append(Number[rand.nextInt(Number.length)]);
/*    */     }
/* 23 */     sb.append(Alphabet[rand.nextInt(Alphabet.length)]);
/* 24 */     return sb.toString();
/*    */   }
/*    */   
/*    */   private static String toSimpleHexString(byte[] bytes) {
/* 28 */     return HexTool.toString(bytes).replace(" ", "").toLowerCase();
/*    */   }
/*    */   
/*    */   private static String hashWithDigest(String in, String digest) {
/*    */     try {
/* 33 */       MessageDigest Digester = MessageDigest.getInstance(digest);
/* 34 */       Digester.update(in.getBytes("UTF-8"), 0, in.length());
/* 35 */       byte[] sha1Hash = Digester.digest();
/* 36 */       return toSimpleHexString(sha1Hash);
/* 37 */     } catch (NoSuchAlgorithmException ex) {
/* 38 */       throw new RuntimeException("Hashing the password failed", ex);
/* 39 */     } catch (UnsupportedEncodingException e) {
/* 40 */       throw new RuntimeException("Encoding the string failed", e);
/*    */     } 
/*    */   }
/*    */   
/*    */   public static String hexSha1(String in) {
/* 45 */     return hashWithDigest(in, "SHA-1");
/*    */   }
/*    */   
/*    */   public static String hexSha512(String in) {
/* 49 */     return hashWithDigest(in, "SHA-512");
/*    */   }
/*    */   
/*    */   public static boolean checkSha1Hash(String hash, String password) {
/* 53 */     return hash.equals(hexSha1(password));
/*    */   }
/*    */   
/*    */   public static boolean checkSaltedSha512Hash(String hash, String password, String salt) {
/* 57 */     return hash.equals(makeSaltedSha512Hash(password, salt));
/*    */   }
/*    */   
/*    */   public static String makeSaltedSha512Hash(String password, String salt) {
/* 61 */     return hexSha512(password + salt);
/*    */   }
/*    */   
/*    */   public static String makeSalt() {
/* 65 */     byte[] salt = new byte[16];
/* 66 */     rand.nextBytes(salt);
/* 67 */     return toSimpleHexString(salt);
/*    */   }
/*    */   
/*    */   public static String rand_s(String in) {
/* 71 */     StringBuilder sb = new StringBuilder();
/* 72 */     for (int i = 0; i < 6; i++) {
/* 73 */       sb.append(rand.nextBoolean() ? Alphabet[rand.nextInt(Alphabet.length)] : Number[rand.nextInt(Number.length)]);
/*    */     }
/* 75 */     return sb.toString() + in;
/*    */   }
/*    */   
/*    */   public static String rand_r(String in) {
/* 79 */     return in.substring(6, 134);
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\client\LoginCrypto.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */